package com.sgb.jicai.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.jicai.base.JiCaiBaseApi;
import com.sgb.jicai.entity.JiCaiJoinInQuotedPriceCompanyEntity;
import com.sgb.jicai.view.fragment.JiCaiQuotedPriceJoinInFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.List;

public class JiCaiQuotedPriceJoinInFraModel  extends ViewModel {

    private JiCaiQuotedPriceJoinInFragment fragment;

    public void getJoinCompanyList(String id) {
        DialogHelper.showProgressDialog(fragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        JiCaiBaseApi.getApi().getJoinInCompanyList(id).enqueue(new ICallBack<BaseEntity<List<JiCaiJoinInQuotedPriceCompanyEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<JiCaiJoinInQuotedPriceCompanyEntity>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null || data.getState() == null) {
                    MToast.showToast(fragment.getContext(), "获取加盟公司失败");
                    return;
                }
                if (data.getState().equals(JiCaiBaseApi.RESPONSE_OK)) {
                    fragment.updateListView(data.getData());
                } else {
                    MToast.showToast(fragment.getContext(),data.getMsg());
                }
            }
        });
    }

    public void setActivity(JiCaiQuotedPriceJoinInFragment jiCaiQuotedPriceJoinInFragment) {
        this.fragment = jiCaiQuotedPriceJoinInFragment;
    }
}
